<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:p="http://primefaces.org/ui"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/pages/home.xhtml">
	<ui:define name="title">
		<h:outputText value="#{text.titUF}" />
	</ui:define>
	<ui:define name="content">
		<p:fieldset id="fieldSetUF" binding="#{ufController.fieldSetUF}">

			<h:inputHidden id="ufId" value="#{ufController.selectedUF.idUf}"/>
			<h:panelGrid id="pnlFields" columns="3">

				<h:outputLabel for="sigla" value="#{text.lblUFSigla}" />
				<p:inputText id="sigla" required="true" size="2" maxlength="2"
					requiredMessage="#{message.requiredUFSigla}"
					value="#{ufController.selectedUF.siglaUf}"/>
				<p:message for="sigla" />
				
				<h:outputLabel for="name" value="#{text.lblUFName}" />
				<p:inputText id="name" required="true" size="50" maxlength="40"
					requiredMessage="#{message.requiredUFName}" 
					value="#{ufController.selectedUF.nomeUf}"/>
				<p:message for="name" />


			</h:panelGrid>

			<p:separator />

			<p:commandButton id="btnNew" value="#{text.btnNew}"
				icon="ui-icon-document"
				actionListener="#{ufController.newUF}" immediate="true"
				update=":frmContent:fieldSetUF"
				onclick="grdUF.unselectAllRows();clearRadioDataTable();"/>
			<p:commandButton id="btnSave" value="#{text.btnSave}" icon="ui-icon-disk"
				update=":frmContent:fieldSetUF, :frmContent:grdUF"
				actionListener="#{ufController.saveUF}" process=":frmContent:fieldSetUF"
				/>
			<p:commandButton id="btnDelete" value="#{text.btnDelete}"
				icon="ui-icon-trash" onclick="dialogDelete.show()"
				binding="#{ufController.btnDelete}"  disabled="true" global="false"/>
			<p:confirmDialog id="dlgConfirmDelete" widgetVar="dialogDelete"
						closable="true" severity="info" appendToBody="true"
						header="#{text.dlgConfirm}"
						message="#{message.confirmDelete}" width="400">
						<p:commandButton id="btnConfirmDelete"
							actionListener="#{ufController.deleteUF}" value="#{text.btnConfirm}"
							icon="ui-icon-check" 
							oncomplete="dialogDelete.hide()"
							update=":frmContent:fieldSetUF, :frmContent:grdUF"
							/>
						<p:commandButton id="btnDeclineDelete"
							onclick="dialogDelete.hide()" value="#{text.btnCancel}"
							icon="ui-icon-cancel" global="false"/>
					</p:confirmDialog>

		</p:fieldset>

		<p:spacer height="25" />

		<p:dataTable id="grdUF" var="uf" 
			value="#{ufController.ufDataModel}" widgetVar="grdUF"
			emptyMessage="#{text.grdEmpty}"
			selection="#{ufController.selectedUF}"
		    paginator="true"
			rows="10" rowsPerPageTemplate="10,25,50"
			paginatorTemplate=" {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			sortBy="#{uf.nomeUf}"
			>

			<p:ajax event="rowSelect" update=":frmContent:fieldSetUF"
				listener="#{ufController.selectUF}" immediate="true"/>

			<p:column selectionMode="single" style="width:18px" />

			<p:column id="colUFSigla" headerText="#{text.lblUFSigla}"
				sortBy="#{uf.siglaUf}" style="width:100px;">
				<h:outputText value="#{uf.siglaUf}" styleClass="cell-align-center"/>
			</p:column>

			<p:column id="colUFNome" headerText="#{text.lblUFName}"
				sortBy="#{uf.nomeUf}">
				<h:outputText value="#{uf.nomeUf}" />
			</p:column>
		</p:dataTable>




	</ui:define>
</ui:composition>
</html>